{extend name='base' /}
{block name='content'}
<body>
<div class="x-nav">
      <span class="layui-breadcrumb">
        <a href="">后台管理</a>
        <a href="">文章管理</a>
        <a>
          <cite>分类列表</cite></a>
      </span>
    <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right"
       href="javascript:location.replace(location.href);" title="刷新">
        <i class="layui-icon" style="line-height:30px">ဂ</i></a>
</div>
<div class="x-body">
    <div class="layui-row">
        <form class="layui-form layui-col-md12 x-so" method="get">
            <input type="text" name="cate_name" placeholder="请输入用户昵称" autocomplete="off" class="layui-input"
                   value="<?php echo $cate_name = isset($_GET['cate_name'])?$_GET['cate_name']:'';?>">
            <button class="layui-btn" lay-submit="" lay-filter="sreach"><i class="layui-icon">&#xe615;</i></button>
        </form>

    </div>
    <xblock>
        <button class="layui-btn" onclick="x_admin_show('添加分类','{:url('category/add')}')"><i class="layui-icon"></i>添加
        </button>
    </xblock>
    <table class="layui-table">
        <thead>
        <tr>

            <th>ID</th>
            <th>分类名称</th>
            <th>添加时间</th>
            <th>修改时间</th>
            <th>状态</th>
            <th>操作</th>
        </thead>
        <tbody>
        {volist name='CateData' id='vo'}
        <tr>
            <td>{$vo.cate_id}</td>
            <td>{$vo.cate_name}</td>
            <td>{$vo.create_time}</td>

            <td>{$vo.update_time}</td>

            <td class="td-status">
                {if $vo.status==1}
                <span class="layui-btn layui-btn-normal layui-btn-xs">正常</span>
                {else /}
                <span class="layui-btn layui-btn-danger layui-btn-xs">禁用</span>
                {/if}
            </td>
            <td class="td-manage">
                <div class="layui-btn-group">
                    {if $vo.status==1}
                    <a onclick="member_stop(this,{$vo.cate_id})" href="javascript:;" class="layui-btn layui-btn-warm layui-btn-xs"
                       stu="{$vo.status}">

                        禁用

                    </a>
                    {else / }
                    <a onclick="member_stop(this,{$vo.cate_id})" href="javascript:;" class="layui-btn layui-btn-info layui-btn-xs"
                       stu="{$vo.status}">

                        启用

                    </a>

                    {/if}
                    <a href="javascript:;" class="layui-btn layui-btn-normal layui-btn-xs" onclick=" x_admin_show('规则编辑','{:url('category/edit','id='.$vo['cate_id'])}')">编辑</a>
                    <a class="layui-btn layui-btn-danger layui-btn-xs" onclick="member_del(this,{$vo.cate_id})" href="javascript:;">删除</a>
                </div>
            </td>
        </tr>
        {/volist}
        </tbody>
    </table>
    <div class="page">
        <div>

        </div>
    </div>

</div>
<script>
    /*用户-停用*/
    function member_stop(obj, id) {
        var sta = $(obj).attr('stu');
        if (sta == 1) {
            var str = '确认要禁用吗？'
        } else {
            var str = '确认要启用吗？'
        }
        layer.confirm(str, function (index) {
            $.ajax({
                url: "{:url('category/upCateSta')}",
                type: 'post',
                dataType: 'json',
                data: {id: id, sta: sta},
                success: function (res) {
                    if (res.code) {
                        layer.msg(res.message, {icon: 6, time: 1000});
                        setTimeout(function () {
                            window.location.reload();
                        }, 1000)

                    } else {
                        layer.msg(res.message, {icon: 2, time: 1000})
                    }
                },
                error: function () {
                    layer.msg('出错了，请稍后再试！！', {icon: 5, time: 1000})
                }
            })


        });
    }

    /*用户-删除*/
    function member_del(obj, id) {
        layer.confirm('确认要删除吗？', function (index) {
            // //发异步删除数据
            $.ajax({
                url: "{:url('category/del')}",
                data: {id: id},
                type: 'post',
                dataType: 'json',
                success: function (res) {
                    if (res.code) {
                        $(obj).parents("tr").remove();
                        layer.msg(res.message, {icon: 6, time: 1000});
                    } else {
                        layer.msg(res.message, {icon: 2, time: 1000})
                    }
                },
                error: function () {
                    layer.msg('出错了，请稍后再试！！', {icon: 5, time: 1000})
                }
            })

        });
    }


</script>

</body>
{/block}